function add(a, b) {
  let i = a.length - 1
  let j = b.length - 1

  let carry = 0
  let res = ''
  while (i >= 0 || j >= 0) {
    let x = (i >= 0) ? (a[i--] - '0') : 0
    let y = (j >= 0) ? (b[j--] - '0') : 0

    let sum = x + y + carry
    sum = (sum > 9) ? (carry = 1, sum - 10) : (carry = 0, sum)

    res = sum + res
  }
  if (carry) {
    res = 1 + res
  }

  return res
}

export default add

